#include <dirent.h> 

void loadModule(char* path)
{
	void* pluginIn = dlopen(path, RTLD_NOW);
	if(pluginIn != (void*)0)
	{
		void* initFunction = dlsym(pluginIn,"hook_interrupt");
		if(pluginIn  == (void*)0)
			printf("shit");
	
		((void (*)(void*))initFunction)(interrupt_handlers);
	}
	else
		printf("Invalid module!");
}

void loadModules()
{
	DIR           *d;
	struct dirent *dir;
	d = opendir("./modules");
	if (d)
	{
    		while ((dir = readdir(d)) != NULL)
    		{

			if(dir->d_type == DT_REG)
			{
				char namebuff[255];
	      			printf("%s\n", dir->d_name);
				strcat(namebuff,"modules/");
				strcat(namebuff,dir->d_name);
				loadModule(&namebuff);
			}
    		}

    		closedir(d);
  	}
	printf("DONE");
}
